package com.twu.biblioteca;

import com.twu.biblioteca.content.BookContent;
import com.twu.biblioteca.content.MovieContent;
import org.junit.After;
import org.junit.Before;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.StringReader;

/**
 * Created by mduemcke on 9/25/14.
 */
public class BiblitotecaTestsAbstract {

    private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();

    private BibliotecaApp app;
    private MovieContent movieContent;
    private BookContent bookContent;

    @Before
    public void setUp() {
        System.setOut(new PrintStream(outContent));
    }

    @After
    public void tearDown() {
        System.setOut(null);
    }

    protected void displayMenuWithInput(String input) {
        input = "123-4567\npassw0rd\n" + input;
        new BibliotecaMenu(getBookContent(), getMovieContent(), new StringReader(input)).displayMenu();
    }

    protected void displayMenuWithInput(String input, String number, String password) {
        input = number + "\n" + password + "\n" + input;
        new BibliotecaMenu(getBookContent(), getMovieContent(), new StringReader(input)).displayMenu();
    }

    protected boolean isStringPrintedOnConsole(String s) {
        return outContent.toString().contains(s);
    }

    protected BookContent getBookContent() {
        if(bookContent == null) {
            bookContent = new BookContent();
        }
        return bookContent;
    }

    protected MovieContent getMovieContent() {
        if(movieContent == null) {
            movieContent = new MovieContent();
        }
        return movieContent;
    }

    protected BibliotecaApp getApp() {
        if(app == null) {
            app = new BibliotecaApp(new PrintStream(outContent), new StringReader(""));
        }
        return app;
    }
}
